package com.beaven.model.model.db;

import com.beaven.model.utils.DataUtil;
import com.raizlabs.android.dbflow.annotation.Column;
import com.raizlabs.android.dbflow.annotation.ForeignKey;
import com.raizlabs.android.dbflow.annotation.PrimaryKey;
import com.raizlabs.android.dbflow.annotation.Table;
import java.io.Serializable;
import java.util.Date;
import java.util.Objects;

/**
 * author: Beaven
 * time: 2017/5/18 14:41
 */
@Table(database = AppDatabase.class) public class Group extends BaseDbModel<Group>
    implements Serializable {

  // 群Id
  @PrimaryKey private String id;

  // 群名称
  @Column private String name;

  // 我在群中的消息通知级别-对象是我当前登录的账户
  @Column private int notifyLevel;

  // 我的加入时间
  @Column private Date joinAt;

  // 信息修改时间
  @Column private Date modifyAt;

  // 创建者外键
  @ForeignKey(tableClass = User.class, stubbedRelationship = true) private User owner;

  // 预留字段，用于界面显示
  public Object holder;

  public String getId() {
    return id;
  }

  public void setId(String id) {
    this.id = id;
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public int getNotifyLevel() {
    return notifyLevel;
  }

  public void setNotifyLevel(int notifyLevel) {
    this.notifyLevel = notifyLevel;
  }

  public Date getJoinAt() {
    return joinAt;
  }

  public void setJoinAt(Date joinAt) {
    this.joinAt = joinAt;
  }

  public Date getModifyAt() {
    return modifyAt;
  }

  public void setModifyAt(Date modifyAt) {
    this.modifyAt = modifyAt;
  }

  public User getOwner() {
    return owner;
  }

  public void setOwner(User owner) {
    this.owner = owner;
  }

  public Object getHolder() {
    return holder;
  }

  public void setHolder(Object holder) {
    this.holder = holder;
  }

  @Override public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;

    Group group = (Group) o;

    return notifyLevel == group.notifyLevel && DataUtil.equals(id, group.id) && DataUtil.equals(name,
        group.name) && DataUtil.equals(joinAt, group.joinAt) && DataUtil.equals(modifyAt,
        group.modifyAt) && DataUtil.equals(owner, group.owner) && DataUtil.equals(holder,
        group.holder);
  }

  @Override public int hashCode() {
    return id != null ? id.hashCode() : 0;
  }

  @Override public boolean isSame(Group old) {
    return DataUtil.equals(id, old.id);
  }

  @Override public boolean isUiContentSame(Group old) {
    return DataUtil.equals(this.name, old.name) && DataUtil.equals(this.holder, old.holder);
  }
}
